import { Asset, Prefab } from "cc";
import { CommonUI } from "../../../[框架]/通用UI/CommonUI";
import { UIManager } from "../../../[框架]/通用UI/UIManager";

export default class TaskResMgr {

    public static ready:boolean = false; // 资源是否加载完成

    public static taskViewPrefab: Asset;

    public static async init(): Promise<boolean> {
        let res = await CommonUI.init();
        if (!res) {
            Guyu.Log.error("TaskResMgr.init() 失败");
            return false;
        }
        return new Promise<boolean>((resolve) => {
            UIManager.instance.getBundle().load("任务/TaskView", Prefab, null, (err, prefab) => {
                if (err) {
                    Guyu.Log.error("任务/TaskView 预制体加载失败", err);
                    resolve(false);
                    return;
                }
                TaskResMgr.taskViewPrefab = prefab;
                Guyu.Log.info("任务/TaskView 预制体加载成功");
                TaskResMgr.ready = true;
                resolve(true);
            });

        });

    }
}